package com.sinoglobal.dumping.util;

import com.sinoglobal.wallet.util.LogUtils;

/**
 * Created by Administrator on 2016/2/18.
 */
public class Dumpling_TimeUtils {

    /**
     *
     * @author zhourihu
     * @createdate 2013-12-24 下午2:23:43
     * @Description: (用一句话描述该方法做什么) 将时间戳转换为 模糊时间 其实一般工具类里对异常不做处理，交给调用者处理
     *            需要转换的时间戳
     * @param create_time
     * @return
     *
     */
    public static String parseTimestampToString(String create_time) {
        long during = 0;
        try {
            during = Long.parseLong(create_time);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return "不久前";
        }
        long nowL = System.currentTimeMillis();// 当前系统毫秒数
        LogUtils.i("当前系统时间戳 毫秒数==" + nowL);
        LogUtils.i("返回的时间戳秒数==" + create_time);
        if (during == 0) {
            return "不久前";
        }
        // during *= 1000;// 传过来的时间戳为妙
        // if(nowL/during>999){//穿过来的为秒
        // during*=1000;
        // }
        during = nowL - during;// 算出距离现在间隔时间 毫秒
        LogUtils.i("距离当前时间毫秒数==" + during);
        during = during / 1000 / 60;// 算出距离现在间隔时间 分钟
        LogUtils.i("距离现在间隔时间 分钟数==" + during);
        if (during <= 0) {// 一分钟前
            return "刚刚";
        } else if (during < 60) {// 由于系统时间差异
            return during + "分钟前";
        } else {
            during = during / 60;// 小时
            if (during < 24) {
                return during + "小时前";
            } else {
                during = during / 24;// 天
                if (during < 30) {
                    return during + "天前";
                } else {
                    during /= 30;// 月
                    if (during < 12) {
                        return during + "月前";
                    } else {
                        during /= 12;// 年
                        return during + "年前";
                    }
                }
            }
        }
    }


}
